package com.category.douyijia.controller;

import com.category.douyijia.model.User;
import com.category.douyijia.services.UserService;
import com.category.douyijia.utils.Encryption;
import com.jfinal.core.Controller;
import com.jfinal.core.NotAction;
import com.jfinal.core.Path;
/**
 * user login management controller.
 * it is using to 
 * user login and management.
 * @author JunfengLiu
 * @version v1.0
 * date time:2021-7-19 18:22:43
 * page path: http://{host address}:{port}/login/*
 */
/*
 * 用户登录管理控制器，
 * 用于用户登录和管理。
 * @author 刘俊沣
 * @version v1.0
 * 时间:2021-7-19 18:22:43
 * 路径: http://{host address}:{port}/login/*
 */
@Path("/login")
public class LoginController extends Controller {
	protected User user = null;
	protected static UserService userService = new UserService();
	/**
	 * user login web page path
	 */
	//用户登录页面
	public void index(){
		//跳转到用户登录页面
		render("login_index.jsp");
	}
	/**
	 * login success
	 */
	//用户登录成功页面
	public void main(){
		
		//跳转到用户登录页面
		render("login_main.jsp");
	}
	/**
	 * user password checked.
	 * 用户密码验证
	 * @param user
	 * user model.
	 * 用户模型
	 */
	@SuppressWarnings("static-access")
	//用户验证
	@NotAction
	public void userLoginCheck(User user){
		String userId = user.getUserId();
		try {
			//用户密码加密
			String userPassword = Encryption.passwordMD5(user.getUserPassword());
			//用户真实信息
			User realUser =  userService.userLogin(userId);
			if (userPassword.equals(realUser.getUserPassword())) {
				//跳转到index页面
				main();
			}else{
				//跳转到login页面
				index();
			}
		} catch (Exception e) {
			// TODO: handle exception
		}
	}
	/**
	 * user message register
	 * and update user message.
	 * 用户修改信息
	 * @param user
	 * user model.
	 * 用户模板
	 */
	//用户注册
	public void register(User user){
		//注册页面
		render("user_register.jsp");
	}
	/**
	 * create the user login model.
	 * is used to login.
	 * 创建用户登录模板
	 */
	//登录模板
	@NotAction
	public void loginModel(){
		keepPara("userId","userPassword");
	}
	/**
	 * create the reset password.
	 * 重置所用用户密码
	 */
	@NotAction
	public void forgetPasswordModel(){
		keepPara("userId","userPassword");
	}
}
